package com.jcj.jcjgateway;

import com.jcj.jcjrpc.core.api.RegistryCenter;
import com.jcj.jcjrpc.core.registry.jcj.JcjRegistryCenter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;

import java.util.Properties;

@Configuration
public class GatewayConfig {

    @Bean
    public RegistryCenter rc() {
        return new JcjRegistryCenter();
    }

    @Bean
    ApplicationRunner runner(@Autowired ApplicationContext applicationContext) {
        return args -> {
            SimpleUrlHandlerMapping handlerMapping = applicationContext.getBean(SimpleUrlHandlerMapping.class);
            Properties mappings = new Properties();
            mappings.put("/ga/**", "gatewayWebHandler");
            handlerMapping.setMappings(mappings);
            handlerMapping.initApplicationContext();
            handlerMapping.setMappings(mappings);
            System.out.println("jcjrpc gateway start");
        };
    }
}
